﻿<%@ Page Title="Đại lý" Language="C#" MasterPageFile="~/App_MasterPages/Aquarius.Master" AutoEventWireup="true" CodeBehind="AgencyManagement.aspx.cs" Inherits="PanasonicWarranty.UI.ManageWarranty.AgencyManagement" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CssContent" runat="server">
    <link href="../css/uploadify.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptContent" runat="server">
    <script src="../js/jquery.uploadify.js" type="text/javascript"></script>
    <script src="../js/pana_authorization.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            RegisterDialog();
            $("[id$='fuImport']").fileUpload({
                'uploader': '../js/uploader.swf',
                'cancelImg': '../img/cancel.png',
                'buttonText': 'Browse Files',
                'script': '../Handler/UpLoad5.ashx',
                'fileDesc': 'Excel file',
                'fileExt': '*.xls;*.xlsx;',
                'multi': false,
                'auto': false,
                'onComplete': function (event, queueID, fileObj, response, data) {
                    $("#spMsgRespone").html(response);
                }
            });
        });
        function SetFullControl(checkbox) {
            var checked = checkbox.checked;
            var id = $(checkbox).parent().find(":hidden").val();
            $.ajax({
                type: "POST",
                url: 'AgencyManagement.aspx/SetFullControl',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: "{'check':" + JSON.stringify(checked) + ", 'agencyId':" + JSON.stringify(id) + "}",
                beforeSend: function () {
                    $("#progress").show();
                },
                complete: function () {
                    $("#progress").hide();
                },
                error: function () {
                    $(checkbox).prop("checked", !checked);
                },
                async: false
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row-fluid">
        <div class="span12">
            <div class="head">
                <div class="isw-grid">
                </div>
                <h1>Điều kiện tìm kiếm</h1>
                <div class="clear"></div>
            </div>
            <div class="block-fluid" style="padding: 10px 0px 5px 10px">
                <table width="100%" cellspacing="0" cellpadding="0" class="">
                    <tbody>
                        <tr>
                            <td style="width:150px">Đại lý</td>
                            <td><asp:TextBox ID="txtSearchAgency" runat="server" /></td>
                        </tr>
                    </tbody>
                </table>
                <div style="text-align: center">
                    <asp:Button ID="btnSearch" runat="server" Text="Tìm kiếm" OnClick="btnSearch_Click" CssClass="btn" />
                </div>
            </div>
        </div>
    </div>
    <div class="head">
        <!-- Tiêu đề của bảng (Thẻ div này chứa nút Addnew và refresh) -->
        <div class="isw-grid"></div>
        <h1>Danh sách đại lý</h1>
        <ul class="buttons">
            <li><asp:LinkButton CssClass="isw-donw_circle" ID="btnExport" runat="server" OnClick="btnExport_Click" ToolTip="Xuất dữ liệu đại lý ra file excel"/></li>
            <li><asp:LinkButton CssClass="isw-download" ID="btnDownload" runat="server" ToolTip="Download mẫu file upload đại lý" onclick="btnDownload_Click"/></li>
            <li><asp:LinkButton CssClass="isw-attachment" ID="btnUpload" runat="server" ToolTip="Import danh sách" OnClientClick="return OpenDialog('dialog2',400);" /></li>
            <li><asp:LinkButton CssClass="isw-plus" ID="lbtnAddNew" runat="server" ToolTip="Thêm mới" OnClick="lbtnAddNew_Click"></asp:LinkButton></li>
        </ul>
        <div class="clear"></div>
    </div>
    <div class="block-fluid table-sorting">
        <asp:GridView ID="grvData" class="dataTables_wrapper table2 dataTable" runat="server"
            AutoGenerateColumns="false" OnRowCommand="grvData_RowCommand">
            <Columns>
                <asp:TemplateField HeaderText="No" ItemStyle-CssClass="STT">
                    <ItemTemplate>
                        <%#Container.DataItemIndex + 1%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField HeaderText="Mã đại lý" DataField="AgencyCode" ItemStyle-CssClass="width3"/>
                <asp:TemplateField HeaderText="Tên đại lý" ItemStyle-CssClass="Description2">
                    <ItemTemplate>
                        <%# Eval("AgencyName").ToString().ShowNameLevel(Eval("Level").ToString())%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField HeaderText="Địa chỉ" DataField="Address" ItemStyle-CssClass="Text" />
                <asp:TemplateField HeaderText="Điện thoại" ItemStyle-CssClass="Phone">
                    <ItemTemplate>
                        <%#pa_Agency.GetPhone(Eval("AgencyID")).Replace(",","<br/>")%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Danh sách tài khoản">
                    <ItemTemplate>
                        <%#pa_Agency.GetUser(Eval("AgencyID")).Replace(",","<br/>")%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Cho phép GHBH" ItemStyle-CssClass="CheckBox">
                    <ItemTemplate>
                        <input type="hidden" value='<%#Eval("AgencyID")%>' />
                        <asp:CheckBox runat="server" Checked='<%#Eval("FullControl")%>' onclick="SetFullControl(this);"  />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Chức năng" ItemStyle-CssClass="Function">
                    <ItemTemplate>
                        <asp:LinkButton ID="lbtnAddChild" Text="Thêm" runat="server"
                            CommandName="AddChild" CommandArgument='<%#Eval("AgencyID")%>' />
                        &nbsp; &nbsp;
                        <asp:LinkButton ID="lbtnEdit" Text="Sửa" runat="server"
                            CommandName="Editing" CommandArgument='<%#Eval("AgencyID")%>' />
                        &nbsp; &nbsp;
                        <asp:LinkButton ID="lbtnDelete" Text="Xóa" runat="server"
                            CommandName="Deleting" CommandArgument='<%#Eval("AgencyID")%>' OnClientClick="return confirm('Bạn có chắc chắn muốn xóa không?');" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    <div class="ui-widget-overlay ui-front" id="progress" style="display:none">
        <img src='<%=ResolveUrl("~/images/loading.gif")%>' alt="Loading..." style="position: fixed; top: 50%; left: 50%" />
    </div>
    <asp:Panel ID="dialogPanel" runat="server">
        <div class="dialog" id="dialog-form" style="display: none; width: 600px; height: 600px;" title="Thông tin đại lý">
            <asp:HiddenField ID="hdfObjectId" runat="server" />
            <div class="block">
                <table width="100%">        
                    <tr>
                        <td>Tên đại lý &nbsp;</td>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" /></td>
                    </tr>
                    <tr>
                        <td>Cấp cha &nbsp;</td>
                        <td><asp:DropDownList ID="ddlParentID" runat="server" /></td>
                    </tr>
                    <tr>
                        <td>Địa chỉ</td>
                        <td><asp:TextBox ID="txtAddres" runat="server" TextMode="MultiLine" /></td>
                    </tr>                
                    <tr>
                        <td>Danh sách sdt</td>
                        <td><asp:TextBox ID="txtPhone" runat="server" onkeypress="return ValidateKeypress(/[\d\,]/, event)" TextMode="MultiLine" /></td>
                    </tr>
                    <tr>
                        <td>Được phép GHBH</td>
                        <td><asp:CheckBox ID="chkFullControl" runat="server" /></td>
                    </tr>
                     <tr>
                        <td>STT</td>
                        <td><asp:TextBox ID="txtOrd" runat="server" onkeypress="return ValidateKeypress(/\d/, event)" /></td>
                    </tr>
                    <tr>
                        <td>Ngưng SD &nbsp;</td>
                        <td><asp:CheckBox ID="chkDisable" runat="server" /></td>
                    </tr>
                </table>
                <div class="dr"><span></span></div>
                <div style="text-align: right">
                    <asp:Button ID="btnSave" CssClass="btn" runat="server" Text="Lưu" OnClick="btnSave_Click" />
                    <input type="button" class="btn" value="Đóng" onclick="$('#dialog-form').dialog('close'); return false;" />
                </div>
            </div>
        </div>
    </asp:Panel>
    
    <div class="dialog" id="dialog2" title="Lựa chọn file Import" style="display: none;">
        <asp:Panel ID="pnl_dialog2" runat="server" CssClass="block">
            <div>
                <asp:FileUpload ID="fuImport" runat="server" />
            </div>
            <div style="text-align:center; color:Red">
                <span id="spMsgRespone"></span>
            </div>
            <div class="dr"><span></span></div>
            <div style="text-align: right">
                <input type="button" class="btn" value="Import" onclick='$("#spMsgRespone").html(""); $("[id$=fuImport]").fileUploadStart();' />
                <asp:Button ID="btnCancel" CssClass="btn" Text="Đóng" OnClick="btnCancel_Click" OnClientClick="$('[id$=fuImport]').fileUploadClearQueue(); $('#dialog2').dialog('close');" runat="server" />
            </div>
        </asp:Panel>
    </div>
</asp:Content>